package com.itheima.mall.dubbo.api.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mall.dubbo.mapper.pms.PmsProductCategoryMapper;
import com.itheima.mall.entity.domain.pms.ProductCategory;
import com.itheima.mall.entity.page.MyPage;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductCategoryServiceImpl extends ServiceImpl<PmsProductCategoryMapper, ProductCategory> implements PmsProductCategoryService {
   @Autowired
   private PmsProductCategoryMapper categoryMapper;
    @Override
    public MyPage<ProductCategory> getPage(Integer parentId, Integer pageNum, Integer pageSize) {
        Page<ProductCategory> categoryPage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<ProductCategory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductCategory::getParentId,parentId);
        categoryMapper.selectPage(categoryPage,lqw);
        MyPage<ProductCategory> myPage = MyPage.init(categoryPage);
        return myPage;
    }

    @Override
    public List<ProductCategory> getByOne() {
        LambdaQueryWrapper<ProductCategory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductCategory::getLevel,0);
        List<ProductCategory> categoryList = categoryMapper.selectList(lqw);
        return categoryList;
    }

    @Override
    public List<ProductCategory> getByTow(Long id) {
        LambdaQueryWrapper<ProductCategory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductCategory::getParentId,id);
        List<ProductCategory> categoryList = categoryMapper.selectList(lqw);
        return categoryList;
    }
}
